import Vue from 'vue'
import VueRouter from 'vue-router'

const UserHome = () => import('@/views/user/home')
const UserProfile = () => import('@/views/user/profile')
const UserAddress = () => import('@/views/user/address')
const UserAddressAdd = () => import('@/views/user/address/add')
const UserInterest = () => import('@/views/user/interest')
const UserSize = () => import('@/views/user/size')
const UserAccount = () => import('@/views/user/account')

Vue.use(VueRouter)

const routes = [
  { path: '/', redirect: '/user' },
  { path: '/user', component: UserHome, meta: { title: '个人中心' } },
  { path: '/user/profile', component: UserProfile, meta: { title: '个人信息' } },
  { path: '/user/address', component: UserAddress, meta: { title: '地址管理' } },
  { path: '/user/address/add', component: UserAddressAdd, meta: { title: '' } },
  { path: '/user/interest', component: UserInterest, meta: { title: '兴趣爱好' } },
  { path: '/user/size', component: UserSize, meta: { title: '我的尺码' } },
  { path: '/user/account', component: UserAccount, meta: { title: '账号安全' } }
]

const router = new VueRouter({
  routes
})

router.beforeEach((to, from, next) => {
  document.title = to.meta.title
  window.FlutterWebTitle && window.FlutterWebTitle.postMessage(document.title)
  next()
})

export default router
